package com.dongdong.controller;

import cn.hutool.core.util.StrUtil;
import com.dongdong.result.Result;

import com.dongdong.result.ResultEnums;
import com.dongdong.service.EmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 王震
 * @date 2024/3/11 15:06
 * @description:邮件的控制器
 */
@RequestMapping("/mail")
@RestController
public class MailController {
    @Autowired
    private EmailService emailService;

    /**  忘记密码 -》根据前端传递的邮箱发送邮件-》点击url -》修改密码
     * 根据邮箱发送url 重新生成密码
     */
    @PostMapping("/sendMail")
    public Result sendMail(@RequestParam("email") String email){
        //如果前端没有传递邮箱，直接返回错误信息  null或空字符串
        if (StrUtil.isBlank(email)){
            return Result.RESPONSE(ResultEnums.EMAIL_NOT_NULL);
        }
        return emailService.sendMail(email);
    }
}
